/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dbhandler;
import entityclasses.roles;

import java.sql.*;
import java.util.ArrayList;
/**
 *
 * Author : Mishal Parmar
 * last change : 21-10-2012
 */
public class AccessRole {
  
public ArrayList accessuser() throws SQLException, ClassNotFoundException         
    {
        String Query;
        
        
        
        Query = "select * from tbl_roles;";
        
        
        DBConnection db = new DBConnection();
        ArrayList<roles> userrole=new ArrayList<roles>();
        ResultSet rs;
        
        
        
        int ab = 0;
        db.connect();
        try {
            rs=db.customQuery(Query);
            
            
           while(rs.next()){
                roles role=new roles();
                role.setRole_id(Integer.parseInt(rs.getString(1)));
                role.setRole_name(rs.getString(2));
                
                userrole.add(role);
                
                
            }
            
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        db.disconnect();
        
        
        return userrole;
    }
public ArrayList accessuserbyid(int id) throws SQLException, ClassNotFoundException         
    {
        String Query;
        
        
        
        Query = "select * from tbl_roles where role_id="+id;
        
        
        DBConnection db = new DBConnection();
        ArrayList<roles> userrole=new ArrayList<roles>();
        ResultSet rs;
        
        
        
        int ab = 0;
        db.connect();
        try {
            rs=db.customQuery(Query);
            
            
           while(rs.next()){
                roles role=new roles();
                role.setRole_id(Integer.parseInt(rs.getString(1)));
                role.setRole_name(rs.getString(2));
                
                userrole.add(role);
                
                
            }
            
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        db.disconnect();
        
        
        return userrole;
    }
public static void main(String [] args) throws SQLException, ClassNotFoundException{
    
    
}
    
}    

